package com.taijihuabao.common.activititasklistener.raisetasklistener;

import com.taijihuabao.modules.entity.DeptUserEntity;
import com.taijihuabao.modules.mapper.DeptUserMapper;
import org.activiti.engine.delegate.DelegateTask;
import org.activiti.engine.delegate.TaskListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

@Component
public class HrManagerListener implements TaskListener {

    @Resource
    private DeptUserMapper deptUserMapper;

    /**
     * 管理员
     */
    private final String GUANLIYUAN = "hr";
    /**
     * 总务部
     */
    private final String ZONGWUBU = "personnelDept";

    @Override
    public void notify(DelegateTask delegateTask) {
        //查询部门
        List<DeptUserEntity> deptUserEntitys = deptUserMapper.selectDeptByDeptCode(ZONGWUBU);
        //根据部门和id查询角色
        for(DeptUserEntity due : deptUserEntitys){
            if (GUANLIYUAN.equals(due.getDeptRole())) {
                delegateTask.addCandidateUser(String.valueOf(due.getUserId()));
            }
        }
    }
}
